﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using net.veekee.common;
using System.Text.RegularExpressions;
using net.veekee.common.rules;
using net.veekee.common.data;
using net.veekee.logprocessor.plugin.input;

namespace net.veekee.logprocessor.plugin.input.pack
{
    public class XMLProcessor : AProcessor<XMLEntry>
    {
        protected override bool ProcessFile(String archive, String filename)
        {
            try
            {
                String tag = Options.GetInstance().Get("input.xml.tag");

                XMLEntry entry = null;
                using (XMLReader xml = new XMLReader(filename))
                {
                    do
                    {
                        entry = new XMLEntry();
                        entry.Data = xml.Next(tag);
                        if (entry.Data == null)
                            break;

                        this.stats_read++;

                        entry.Line = this.stats_read;
                        entry.Filename = filename;
                        entry.Archive = archive;

                        this.OnNewItem(entry);
                    } while ((entry.Data = xml.Next(tag)) != null);
                }
                return true;
            }
            catch (Exception e)
            {
                Log.GetInstance().Debug(e.ToString());
            }
            finally
            {
                Log.GetInstance().WriteProgressBarEnd();
            }
            return false;
        }
    }
}
